﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UI.Core;
using BO;

namespace UI
{
    public partial class ExceptionExShowForm : FormBase
    {
        public ExceptionExShowForm(ExceptionEx Exp)
        {
            InitializeComponent();
            this.CenterToScreen();
            tbErr.ScrollBars = RichTextBoxScrollBars.Vertical;

            externExp = Exp;
        }

        private ExceptionEx externExp;
        private StringBuilder expMsg;
        protected override void OnLoad(EventArgs e)
        {
            if (externExp == null)
                return;
            expMsg = new StringBuilder();
            HandleExcption(externExp);
            tbErr.Text = expMsg.ToString();
            tbErr.ForeColor = Color.Blue;
            base.OnLoad(e);
          

        }

        void HandleExcption(Exception ex)
        {
            expMsg.AppendLine("________MSG________________");
            expMsg.AppendLine(ex.Message);
            expMsg.AppendLine("______________________________");
            expMsg.AppendLine("________StackTrace__________");
            expMsg.AppendLine(ex.StackTrace);
            expMsg.AppendLine("______________________________");
            if (ex.InnerException != null)
                HandleExcption(ex.InnerException);
            Application.UseWaitCursor = false;
        }

        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);
            Cursor = Cursors.Default;
        }
        
    }
}
